<!DOCTYPE html>
<html lang="en-US">
<head>
	<meta charset="UTF-8">
	<title>1-2 只能输入数字的文本框</title>
	<style>
		*{
			margin: 0;
			padding: 0;
		}
	</style>
	<script type="text/javascript">
		window.onload=function(){
			var shuru=document.querySelectorAll('input')[0];
			shuru.onkeydown=function(ev){
				var oEvent=ev||event;

				if (oEvent.keyCode!=8 && oEvent.keyCode!=37 && oEvent.keyCode!=39 && (oEvent.keyCode<48 || oEvent.keyCode>57)) {
					return false;
				}
			};
		};
	</script>
</head>
<body>
	<input type="text">
	<input type="submit" value="提交">
</body>
</html>